package com.amt.olcacon;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUrlConverter {
    
    public static String convertUrlToFilename(String url) {
        // 使用正则表达式提取所有参数
        Pattern pattern = Pattern.compile("fileName=([^&]*)&fut=([^&]*)&ai=([^&]*)&con=([^&]*)&fpp=/([^&]*)");
        Matcher matcher = pattern.matcher(url);
        
        if (matcher.find()) {
            String fileName = matcher.group(1).replace(".xlsx", "");
            String fut = matcher.group(2);
            String ai = matcher.group(3);
            String con = matcher.group(4);
            String fpp = matcher.group(5);
            
            return String.format("%s/%s_fut%s_ai%s_con%s.xlsx", 
                               fpp, fileName, fut, ai, con);
        }
        
        throw new IllegalArgumentException("URL格式不符合预期模式");
    }
    
    public static void main(String[] args) {
        String url = "/upload/工序导入模板v2.0.xlsx?fileName=工序导入模板v2.0.xlsx&fut=1757397452561&ai=5cee4b16-a895-4d29-a002-c2845cf526ec&con=lcap_default_connection&fpp=/official_website";
        
        String result = convertUrlToFilename(url);
        System.out.println("转换结果: " + result);
    }
}